package com.carkeeper.controller;

import com.carkeeper.dto.ClassPropertiesDTO;
import com.carkeeper.pojo.ClassPropertiesPO;
import com.carkeeper.service.ClassPropertiesService;
import com.carkeeper.vo.Pager;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/classProperties")
public class ClassPropertiesController {

    private final ClassPropertiesService classPropertiesService;

    public ClassPropertiesController(ClassPropertiesService classPropertiesService) {
        this.classPropertiesService = classPropertiesService;
    }

    /*
     * 新增二级配件分类
     * @author xxj
     * @date 2020/6/1-12:02
     * @param classPropertiesPO
     * @return java.lang.String
     */
    @PostMapping
    public String addClassProperties(@RequestBody ClassPropertiesPO classPropertiesPO) {
        return classPropertiesService.addClassProperties(classPropertiesPO);
    }

    /*
     * 根据ID删除二级配件分类
     * @author xxj
     * @date 2020/6/1-12:05
     * @param id
     * @return java.lang.String
     */
    @DeleteMapping("/{id}")
    public String deleteClassProperties(@PathVariable Long id) {
        return classPropertiesService.deleteClassProperties(id);
    }

    /*
     * 更新二级配件分类
     * @author xxj
     * @date 2020/6/1-12:14
     * @param id
     * @param classPropertiesPO
     * @return java.lang.String
     */
    @PutMapping("/{id}")
    public String updateClassProperties(
            @PathVariable Long id,
            @RequestBody ClassPropertiesPO classPropertiesPO) {
        return classPropertiesService.updateClassProperties(id, classPropertiesPO);
    }
    /*
     * 根据id获取二级分类详情
     * @author xxj
     * @date 2020/6/1-15:26
     * @param id
     * @return com.carkeeper.dto.ClassPropertiesDTO
     */
    @GetMapping("/{id}")
    public ClassPropertiesDTO getClassPropertiesById(@PathVariable Long id) {
        return classPropertiesService.getClassPropertiesById(id);
    }
    /*
     * 获取二级分类分页详情
     * @author xxj
     * @date 2020/6/1-16:29
     * @param page
 * @param pagesize
 * @param classId
     * @return com.carkeeper.vo.Pager<com.carkeeper.dto.ClassPropertiesDTO>
     */ 
    @GetMapping
    public Pager<ClassPropertiesDTO> getClassPropertiesByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "pagesize",defaultValue = "5") Integer pagesize,
            @RequestParam(value = "classId",required = false) Integer classId) {
        return classPropertiesService.getClassPropertiesByPage(page,pagesize,classId);
    }
}
